<template>
  <div>
    <div style="margin: 0 5%;">
    <el-alert
      style="margin-top: 50px;"
      title="未审核"
      :closable="false"
      type="info"
      v-if="formData.examineStatus==0"
      show-icon
    >
    </el-alert>

    <el-alert
      style="margin-top: 50px;"
      title="审核已通过"
      :closable="false"
      type="success"
      v-if="formData.examineStatus==3"
      show-icon
    >
    </el-alert>

    <el-alert
      style="margin-top: 50px;"
      title="待审核"
      :closable="false"
      type="info"
      v-if="formData.examineStatus==1"
      show-icon
    ></el-alert>

    <el-alert
      style="margin-top: 50px;"
      title="审核未通过，待修改中。。。"
      :closable="false"
      type="error"
      v-if="formData.examineStatus==2"
      show-icon
    >
    </el-alert>
    </div>
    <student-info :stu-data="formData"></student-info>
    <el-row :gutter="100">
      <el-col :span="12" :push="8" style="margin: 40px 0;" v-if="formData.examineStatus==1">
          <el-button style="margin: 0 50px;" type="primary" @click="examineSuccess" >审核通过</el-button>
          <el-button style="margin: 0 50px;" type="danger" @click="examineError" >审核不通过</el-button>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import {getStudentDetailInfo,changeStudentExamineStatus} from "@/api/mentor/student"

  import {getInfo} from "@/api/login"
  import {getAllSubject} from "../../../api/mentor/subject";

  import studentInfo from '../../../components/StudentInfo'

  export default {
    components: {studentInfo},
    props: [],
    data() {
      return {
        formData: {
          subId:undefined,
          stuName: undefined,
          stuSno: undefined,
          stuGender: undefined,
          stuExamId: undefined,
          stuCardId: undefined,
          stuBirth: undefined,
          stuGraduateDate: undefined,
          stuResidenceAddress: undefined,
          examineStatus: undefined,
          stuWorkingCompany: undefined,
          stuMobile: undefined,
          stuEmail: undefined,
          stuUgSchool: undefined,
          stuUgMajor: undefined,
          stuUgTime: undefined,
          stuPgFirstWishSchool: undefined,
          stuPgFirstWishMajor: undefined,
          stuPgFirstWishDirection: undefined,
          stuPgExamForeignScore: undefined,
          stuPgExamPolitical: undefined,
          stuPgExamMath: undefined,
          stuPgExamSchool: undefined,
          stuPgExamTotal: undefined,
          stuPgReview: undefined,
          stuPgTotal: undefined,
          stuPgSecondMajor: undefined,
          stuPgSecondDirection: undefined,
          stuSourceType: undefined,
          stuDependence: null,
          stuResume:undefined,
          stuReward:undefined
        },
        subjectList:[],
        stuGenderOptions: [{
          "label": "女",
          "value": 0
        }, {
          "label": "男",
          "value": 1
        }],
        studentId:undefined,
        adminName:undefined,
        isIns:false,
        roles:undefined
      }
    },
    computed: {},
    async created() {
      this.studentId = this.$route.params.id
      await this.getStudentDetailInfo()
      await this.getAllSubject()
      const res = await getInfo()
      this.roles = res.roles
      this.adminName = res.user.nickName
      this.isIns = this.checkIsIns()
    },
    mounted() {},
    methods: {
      async getStudentDetailInfo() {
        const res = await getStudentDetailInfo(this.studentId)
        this.formData = res.data
      },
      //审核通过
      async examineSuccess() {
        const res = await changeStudentExamineStatus(this.adminName,3, this.studentId,"审核通过")
        // console.log(res)
        if (res.code!=200){
          this.$message.error(res.msg)
          return
        }
        await this.$router.push("/student/list")
      },
      //审核不通过
      async examineError() {
        const confirm = await this.$prompt('请输入未通过审核原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        })
        if (confirm.value==null){
          this.$message.warning("审核原因不能为空")
          return
        }
        if (confirm.action!="confirm"){
          return
        }
        const res = await changeStudentExamineStatus(this.adminName,2, this.studentId, confirm.value)
        if (res.code!=200){
          this.$message.error(res.msg)
          return
        }
        await this.$router.push("/student/list")
      },
      async getAllSubject() {
        const res = await getAllSubject()
        this.subjectList = res.data
        // console.log(res)
      },
      checkIsIns(){
        // console.log(this.roles)
        for(let role in this.roles){
          if (role=='instructor'){
            return true
          }
        }
        return false
      }
    }
  }

</script>
<style scoped>
  .el-upload__tip {
    line-height: 1.2;
  }

</style>
